﻿using System;

namespace EventExample
{
    class PublishingHouse
    {
        //public delegate void PublishMegazine(object sender, NewMagazineEventArgs e);

        //public event PublishMegazine NewMagazine;

        public event EventHandler<NewMagazineEventArgs> NewMagazine;

        protected virtual void OnNewMagazine(NewMagazineEventArgs e)
        {
            if (NewMagazine != null)
                NewMagazine(this, e);

            //EventHandler<NewMagazineEventArgs> del = NewMagazine as EventHandler<NewMagazineEventArgs>;

            //if (del != null)
            //    del(this, e);
        }

        public void PublishMagazine(string magazineName, int magazineNumber, string text, int count)
        {
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Magazine: {0}, volume: {1}\n{2}", magazineName, magazineNumber, text);
            }
            Console.WriteLine();
            Console.WriteLine("{0} was printed", magazineName);
            Console.WriteLine();
            NewMagazineEventArgs e = new NewMagazineEventArgs(magazineName, magazineNumber);
            OnNewMagazine(e);
        }
    }
}